package com.bjsxt.array;

import java.util.Arrays;

public class TestComparable {
    public static void main(String[] args) {
        Man2[] mans ={new Man2(1001,"dsg",17),new Man2(1002,"hasgfd",10),new Man2(1003,"efg",38)};
        Arrays.sort(mans);
        System.out.println(Arrays.toString(mans));
    }
}

class Man2 implements Comparable{
    private int id;
    private String name;
    private int age;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return String.valueOf(age);
    }

    public Man2(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public int compareTo(Object o) {
        Man2 man =(Man2) o;
        if (this.age<man.getAge()){
            return -1;
        }
        if (this.age>man.getAge()){
            return 1;
        }
        return 0;
    }
}